<?php

namespace App\Models;

use App\Facades\MoneyPlatformRequestFacade;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\RepayRecordMonth
 *
 * @property int $id
 * @property int $uid 关联用户id
 * @property int $summary_id 关联还款表id
 * @property int $record_id 关联还款记录表id
 * @property int $bank_cards_id 关联user_bank_cards银行卡id
 * @property string $third_record_id 资方接口返回,月保请求id
 * @property string $trade_no 平台内唯一流水号
 * @property int $amount 月保费,以分为单位
 * @property int $period 当前期数,0为全部还清记录
 * @property string $failure 失败原因
 * @property int $status 蔚捷接口状态 1:待处理,2:处理中,3:失败,4:成功
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth whereAmount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth whereBankCardsId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth whereFailure($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth wherePeriod($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth whereRecordId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth whereSummaryId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth whereThirdRecordId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth whereTradeNo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth whereUid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth whereUpdatedAt($value)
 * @mixin \Eloquent
 * @property string|null $apply_time 接口申请时间
 * @property string|null $status_time 接口处理成功/失败时间
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth whereApplyTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth whereStatusTime($value)
 * @property-read \App\Models\RepayRecord $record
 * @property-read \App\Models\UserCertOcr $relationUserCertOcrs
 * @property-read \App\Models\User $relationUsers
 * @property int $repay_type 1=>app中用户手动点击还款,2=>app中自动还款
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\RepayRecordMonth whereRepayType($value)
 */
class RepayRecordMonth extends Model
{
    //蔚捷月报接口状态 1:待处理,2:处理中,3:失败,4:成功
    const STATUS_ONE = 1;
    const STATUS_TWO = 2;
    const STATUS_THREE = 3;
    const STATUS_FOUR = 4;

    /**
     * 不可被批量赋值的属性。
     *
     * @var array
     */
    protected $guarded = [];

    /**
     * Description: 设置资方记录利息费
     * Author: Gxs
     * @param $value
     */
    public function setAmountAttribute($value)
    {
        $this->attributes['amount'] = (int)bcmul($value, 100);
    }

    /**
     * Description: 获取资方记录利息费
     * Author: Gxs
     * @param $value
     * @return int
     */
    public function getAmountAttribute($value)
    {
        return bcdiv($value, 100, 2);
    }

    /**
     * Description: 关联记录接口表
     * Author: Gxs
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function record()
    {
        return $this->hasOne('App\Models\RepayRecord', 'id', 'record_id');
    }

    /**
     * Description: 反关summary
     * Author: Gxs
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function relationSummary()
    {
        return $this->belongsTo('App\Models\RepaySummary', 'summary_id', 'id');
    }

    /**
     * Description: 反关用户表
     * Author: Gxs
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function relationUsers()
    {
        return $this->belongsTo('App\Models\User', 'uid', 'id');
    }

    /**
     * Description: 反关用户身份证实名表
     * Author: Gxs
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function relationUserCertOcrs()
    {
        return $this->belongsTo('App\Models\UserCertOcr', 'uid', 'user_id');
    }

}
